package com.qyhl.module_activities.act;


import com.qyhl.module_activities.R;
import com.qyhl.module_activities.app.ActivitiesApplication;
import com.qyhl.module_activities.common.ActUrl;
import com.qyhl.webtv.basiclib.utils.ContextUtilts;
import com.qyhl.webtv.basiclib.utils.NetUtil;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.act.ActivityListTempBean;

import java.util.List;

/**
 * Created by qyhl2 on 2017/12/6.
 */

public class ActivityTempModel implements ActivityTempContract.ActivityTempModel {


    private ActivityTempContract.ActivityTempPresenter presenter;

    public ActivityTempModel(ActivityTempContract.ActivityTempPresenter presenter) {
        this.presenter = presenter;
    }

    /**
     * 获取活动列表
     */
    @Override
    public void getData(int actId) {
        if (NetUtil.isNetworkAvalible(ActivitiesApplication.getApp())) {

            EasyHttp.get(ActUrl.ACTIVITY_LIST)
                    .params("siteId", CommonUtils.getInstance().getSite()+"")
                    .params("actId", String.valueOf(actId))
                    .execute(new SimpleCallBack<List<ActivityListTempBean>>() {
                        @Override
                        public void onError(ApiException e) {
                            presenter.onError(2, ContextUtilts.getInstance().getmContext().getString(R.string.error_str));
                        }

                        @Override
                        public void onSuccess(List<ActivityListTempBean> activityListTempBeans) {
                            presenter.onSuccess(activityListTempBeans);
                        }
                    });

        } else {
            presenter.onError(1, "无网络连接，请检查您的网络...");
        }
    }

    @Override
    public void getCollectionData(int actId) {
        if (NetUtil.isNetworkAvalible(ActivitiesApplication.getApp())) {
            String userName = CommonUtils.getInstance().getUserName();

            EasyHttp.get(ActUrl.ACTIVITY_COLLECTIONLIST)
                    .params("phone", userName)
                    .params("actId", String.valueOf(actId))
                    .execute(new SimpleCallBack<List<ActivityListTempBean>>() {
                        @Override
                        public void onError(ApiException e) {
                            presenter.onError(2, ContextUtilts.getInstance().getmContext().getString(R.string.error_str));
                        }

                        @Override
                        public void onSuccess(List<ActivityListTempBean> activityListTempBeans) {
                            presenter.onSuccess(activityListTempBeans);
                        }
                    });
        } else {
            presenter.onError(1, "无网络连接，请检查您的网络...");
        }
    }

    @Override
    public void getApplyData(int actId) {
        if (NetUtil.isNetworkAvalible(ActivitiesApplication.getApp())) {
            String userName = CommonUtils.getInstance().getUserName();

            EasyHttp.get(ActUrl.ACTIVITY_SING_LIST)
                    .params("phone", userName)
                    .params("actId", String.valueOf(actId))
                    .execute(new SimpleCallBack<List<ActivityListTempBean>>() {
                        @Override
                        public void onError(ApiException e) {
                            presenter.onError(2, ContextUtilts.getInstance().getmContext().getString(R.string.error_str));
                        }

                        @Override
                        public void onSuccess(List<ActivityListTempBean> activityListTempBeans) {
                            presenter.onSuccess(activityListTempBeans);
                        }
                    });

        } else {
            presenter.onError(1, "无网络连接，请检查您的网络...");
        }
    }
}
